<?php
include('../config.php');
include(PUNG_ROOT . '/admin/header.php');
include(PUNG_ROOT . '/admin/config_manager.php');

$adminmenu = array(
LANG_029 => 'themes.php'
);

$dir = PUNG_ROOT . '/templates/';
$dh = opendir($dir);
$files = array();

while(false !== ($filename = readdir($dh)))
{
	$files[] = $filename;
}

unset($files['0']);
unset($files['1']);
sort($files);

if(isset($_POST['submit']))
{
	$values = array(array('THEME', $_POST['theme']));
	
	open_config_file();
	write_config_file($values);
	close_config_file();
	
	redirect_with_message('msg', 'LANG_046');
}

include(PUNG_ROOT . '/admin/head.php');
?>

<h3><?php print LANG_030; ?></h3>

<form action="" method="post">
<table width="100%">
<tr>
	<th><?php print LANG_031; ?></th>
	<th width="80"><?php print LANG_032; ?></th>
	<th width="80"><?php print LANG_033; ?></th>
	<th width="80">&nbsp;</th>
</tr>
<?php foreach($files as $theme) { ?>
<tr>
	<td><?php print $theme; ?></td>
	<td>
	<?php
	if(is_file(PUNG_ROOT . '/templates/' . $theme . '/screenshot.png'))
	{
		print '<img src="../templates/' . $theme . '/screenshot.png" alt="Screenshot" />';
	}
	else
	{
		print '<img src="../images/admin_img/noscreen.png" alt="Screenshot" />';
	}
	?>
	</td>
	<td align="center"><a href="../templates/<?php print $theme; ?>/LICENSE.txt" 
	target="_blank" title="<?php print LANG_034; ?>"><img 
	src="../images/admin_img/license.png" alt="<?php print LANG_034; ?>" /></a></td>
	<td align="center"><input type="radio" value="<?php print $theme; ?>" 
	name="theme"<?php if($theme == THEME){print ' checked="checked"';} ?> /></td>
</tr>
<?php } ?>
</table>
<br />
<input type="submit" value="<?php print LANG_035; ?>" name="submit" class="form_button" />
</form>

<?php
include(PUNG_ROOT . '/admin/footer.php');
?>